using MediatR;
using SumerCoreDevOps.Application.Workflows.Queries;
using SumerCoreDevOps.Domain.Entities;
using SumerCoreDevOps.Infrastructure.Workflow;

namespace SumerCoreDevOps.Application.Workflows.Handlers;

/// <summary>
/// 获取所有启用的工作流查询处理器
/// </summary>
public class GetWorkflowsQueryHandler : IRequestHandler<GetWorkflowsQuery, List<WorkflowDefinition>>
{
    private readonly WorkflowDefinitionManager _definitionManager;

    public GetWorkflowsQueryHandler(WorkflowDefinitionManager definitionManager)
    {
        _definitionManager = definitionManager;
    }

    public async Task<List<WorkflowDefinition>> Handle(GetWorkflowsQuery request, CancellationToken cancellationToken)
    {
        return await _definitionManager.GetEnabledWorkflowsAsync();
    }
}
